﻿#include <iostream>
#include <vector>
using namespace std;

class Solution
{
public:
    // 860. 柠檬水找零
    bool lemonadeChange(vector<int>& bills)
    {
        int five = 0, ten = 0;
        for (auto x : bills)
        {
            if (x == 5)
                five++;
            else if (x == 10)
            {
                if (five == 0)
                    return false;
                five--;
                ten++;
            }
            else
            {
                if (five && ten)
                {
                    five--;
                    ten--;
                }
                else if (five >= 3)
                {
                    five -= 3;
                }
                else
                {
                    return false;
                }
            }
        }
        return true;
    }
};

int main()
{
    vector<int> bills{ 5,5,5,10,20 };
    cout << Solution().lemonadeChange(bills) << endl;

    return 0;
}